using IQIGame.Onigao.Framework;

namespace IQIGame.Onigao.GamePlay
{
    public class LevelBuffDisplayComponent : LevelEntityBaseComponent
    {
        public override uint MaxStore => 100;
        private LevelBuffHolder _buffHolder;

        public override void OnCreate(TEntity entity)
        {
            base.OnCreate(entity);
            var dynData = this.entity.GetDynEntityData();
            if (dynData is DynLevelHeroEntity) //英雄实体是玩家化身，一对一关系
            {
                _buffHolder = LevelPlayUtil.GetDynLevelPlayer().buffHolder;
            }
            else if (dynData is DynLevelEntity dynEntity)
            {
                _buffHolder = dynEntity.buffHolder;
            }
            else
            {
                LogGame.LogError($"不支持的实体类型：{entity.GetType().Name}");
                return;
            }

            _buffHolder.onBuffRemove += OnBuffRemoved;
            _buffHolder.onBuffUpdate += OnBuffUpdated;
        }

        private void OnBuffUpdated(LevelBuffData data, bool isNew, int addStack)
        {

        }

        private void OnBuffRemoved(LevelBuffData data)
        {

        }

        public override void OnPoolReset()
        {
            if (_buffHolder == null)
            {
                return;
            }
            _buffHolder.onBuffRemove -= OnBuffRemoved;
            _buffHolder.onBuffUpdate -= OnBuffUpdated;
            _buffHolder = null;
        }
    }
}
